#include "SceneManager.h"

SceneManager* SceneManager::m_pInstance = 0;

SceneManager::~SceneManager()
{
	SAFE_DEL(m_pCurrentScene);
	SAFE_DEL(m_pNextScene);
}

__VOID SceneManager::Update(__FLOAT deltaTime, __BOOL isPause)
{
	//Check need to switch scene
	if (m_pCurrentScene != m_pNextScene)
	{
		//End current scene
		if (m_pCurrentScene)
		{
			m_pCurrentScene->Exit();
			SAFE_DEL(m_pCurrentScene);
		}
		//Init new scene
		if (m_pNextScene)
		{
			m_pNextScene->Init();
		}
		//Update new scene
		m_pCurrentScene = m_pNextScene;
	}

	//Update scene
	if (m_pCurrentScene)
	{
		if (!isPause)
		{
			m_pCurrentScene->Update(deltaTime);
		}
		m_pCurrentScene->Draw();
	}
}

__VOID SceneManager::Switch(Scene* pScene)
{
	m_pNextScene = pScene;
}